function error(msg) {
	layer.alert(msg, {icon: 2});
}

function ok(msg){
	if (!!!msg) {
		msg = "操作成功";
	}
	parent.layer.msg(msg,{icon:1, time: 1500, skin: 'layui-layer-molv'});
}

function okalert(msg) {
	layer.alert(msg, {icon: 1});
}
/**
 * @url url
 * @data 参数，json对象
 * @success 成功回调函数
 */
k.layer.add = function(url, successHandler, config) {
	if (!config) {
		config = {};
	}
	layer.open({
		title: config.title || '新增',
	    type: 2,
	    skin: 'layui-layer-rim', //加上边框
	    area: [layer_default_width, layer_default_height], //宽高
	    content: url,
	    btn: ['确定', '取消'],
	    yes: function(index, layero){ //或者使用btn1
	    	var detailForm = layer.getChildFrame('form', index);
	    	console.log(detailForm);
            var iframeWin = window[layero.find('iframe')[0]['name']];
	    	if(iframeWin.validateInput()){
                detailForm.ajaxSubmit({
                    success: function(data) {
                        if (successHandler) {
                            successHandler(data)
                        } else {
                            if (isSuccess(data)) {
                                layer.close(index);
                                reload();
                            } else {
                            }
                        }
                    }
                });
			}
	    }, cancel: function(index){ //或者使用btn2
	        //按钮【按钮二】的回调
	    },
	    end: function() {
	    	// alert('end')
	    }
	});
}
k.layer.del = function (url, id) {
    var ids = [id];
    layer.confirm('确定要禁用吗？', {icon: 3, title: '提示'}, function (index) {
        $.ajax({
            url: url,
            type: "POST",
            data: {
                ids: ids.join(",")
            },
            success: function (data) {
                if (isSuccess(data)) {
                    layer.close(index);
                    reload();
                }
            }
        });
    });
};

k.layer.edit = function(url, successHandler, config) {
	if (!config) {
		config = {};
	}
	layer.open({
		title: config.title || '详情',
	    type: 2,
	    skin: 'layui-layer-rim', //加上边框
	    area: [layer_default_width, layer_default_height], //宽高
	    content: url,
	    btn: ['确定', '取消'],
	    yes: function(index, layero){ //或者使用btn1
	    	var detailForm = layer.getChildFrame('form', index);
	    	console.log(detailForm);
	    	detailForm.ajaxSubmit({
	    		success: function(data) {
	    			if (successHandler) {
	    				successHandler(data)
	    			} else {
	    				if (isSuccess(data)) {
		    				layer.close(index)
		    				reload();
		    			} else {
		    			}
	    			}
	    		}
	    	});
	    }, cancel: function(index){ //或者使用btn2
	        //按钮【按钮二】的回调
	    },
	    end: function() {
	    	// alert('end')
	    }
	});
};

k.layer.editAndReloadTop = function(url, successHandler, config) {
    if (!config) {
        config = {};
    }
    layer.open({
        title: config.title || '详情',
        type: 2,
        skin: 'layui-layer-rim', //加上边框
        area: [layer_default_width, layer_default_height], //宽高
        content: url,
        btn: ['确定', '取消'],
        yes: function(index, layero){ //或者使用btn1
            var detailForm = layer.getChildFrame('form', index);
            console.log(detailForm);
            detailForm.ajaxSubmit({
                success: function(data) {
                    if (successHandler) {
                        successHandler(data)
                    } else {
                        if (isSuccess(data)) {
                            data = JSON.parse(data);
                            top.$("#customerCount").html(data.customerCount);
                            top.$("#remainPackageCount").html(data.data.remainPackageCount);
                            top.$("#newlyEnrolledCount").html(data.data.newlyEnrolledCount);
                            layer.close(index)
                            reload();
                        } else {
                        }
                    }
                }
            });
        }, cancel: function(index){ //或者使用btn2
            //按钮【按钮二】的回调
        },
        end: function() {
            // alert('end')
        }
    });
};

k.layer.detail = function (url) {
    layer.open({
        title: '查看',
        type: 2,
        skin: 'layui-layer-rim', //加上边框
        area: [layer_default_width, layer_default_height], //宽高
        content: url,
        btn: ['保存','关闭'],
        yes: function (index, layero) {
            var detailForm = layer.getChildFrame('form', index);
            var iframeWin = window[layero.find('iframe')[0]['name']];
            if(iframeWin.validateInput()){
                detailForm.ajaxSubmit({
                    success: function(data) {
                        if (isSuccess(data)) {
                            layer.close(index);
                            reload();
                        }
                    }
                });
			}
        },
        cancel: function(index, layero){ //或者使用btn1
            layer.close(index);
        }
    });
};

k.layer.showDetail = function (url) {
    layer.open({
        title: '查看',
        type: 2,
        skin: 'layui-layer-rim', //加上边框
        area: [layer_default_width, layer_default_height], //宽高
        content: url,
        btn: ['关闭'],
        yes: function (index, layero) {
            layer.close(index);
        },
        cancel: function(index, layero){ //或者使用btn1
        }
    });
};

k.layer.updateStatus = function (url, id, status) {
    layer.confirm('确定要' + (status === 0 ? '禁用' : '启用') + '吗？', {icon: 3, title: '提示'}, function (index) {
        $.ajax({
            url: url,
            type: "POST",
            data: {
                id: id,
				status: status
            },
            success: function (data) {
                if (isSuccess(data)) {
                    layer.close(index);
                    reload();
                }
            }
        });
    });
};